package com.xuanheng.pojo;

/**
 * Created by liyunhan on 2017/11/4.
 */

public class ScaleData {

    private int type;
    private String weightUnit;
    private double weight;
    private double impedance;
    private int resH;
    private int resL;
    private int sn;
    private boolean battery;




    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public String getWeightUnit() {
        return weightUnit;
    }

    public void setWeightUnit(String weightUnit) {
        this.weightUnit = weightUnit;
    }

    public double getWeight() {
        return weight;
    }

    public void setWeight(double weight) {
        this.weight = weight;
    }

    public double getImpedance() {
        return impedance;
    }

    public void setImpedance(double impedance) {
        this.impedance = impedance;
    }

    public int getResH() {
        return resH;
    }

    public void setResH(int resH) {
        this.resH = resH;
    }

    public int getResL() {
        return resL;
    }

    public void setResL(int resL) {
        this.resL = resL;
    }

    public int getSn() {
        return sn;
    }

    public void setSn(int sn) {
        this.sn = sn;
    }

    public boolean isBattery() {
        return battery;
    }

    public void setBattery(boolean battery) {
        this.battery = battery;
    }


    public static ScaleData fromByteArray(byte[] bytes){
        ScaleData scaleData=new ScaleData();
        if(bytes!=null&&bytes.length==14){
            if((bytes[1]&0xff)==0xdd){
                byte bweightUnit=bytes[2];
                if(bweightUnit==0){
                    scaleData.weightUnit="kg";
                }else if((bweightUnit&0xff)==0x10){
                    scaleData.weightUnit="lb";
                }else if((bweightUnit&0xff)==0x11){
                    scaleData.weightUnit="st";
                }
                byte bweight=bytes[3];
                int wei=bweight;
                scaleData.weight=((double) wei)/10d;
                byte i1=bytes[4];
                byte i2=bytes[5];
                byte i3=bytes[6];
                byte i4=bytes[7];
                int rh=bytes[8];
                int rl=bytes[9];
                if(bytes[11]==0x80){
                    scaleData.battery=true;
                }else if(bytes[11]==0x81){
                    scaleData.battery=false;
                }
            }
        }

        return scaleData;
    }

    @Override
    public String toString() {
        return "Records{" +
                "体重=" + weight +" "+weightUnit+
                ", BMI=" + 0 +
                ", 骨骼=" + 0 +
                ", 脂肪=" + 0 +
                ", 肌肉=" + 0 +
                ", 水分=" + 0 +
                ", 内脏脂肪=" + 0 +
                ", BMR=" + 0 +
                '}';
    }
}
